<template>
  <div v-if="showNotice" class="mobile_notice_overlay">
    <div class="mobile_notice_content">
      <div class="card_glow"></div>
      <div class="mobile_notice_header">
        <button @click="closeNotice" class="close_btn">×</button>
      </div>
      <div class="mobile_notice_body">
        <div class="icon">
          <svg xmlns="http://www.w3.org/2000/svg" width="48" height="48" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
            <line x1="12" y1="9" x2="12" y2="13"></line>
            <line x1="12" y1="17" x2="12.01" y2="17"></line>
          </svg>
        </div>
        <p class="notice_subtitle">我们检测到您正在使用小屏幕设备访问</p>
        
        <div class="rotate_instruction">
          <div class="phone_portrait">
            <div class="phone_screen"></div>
            <div class="phone_home_button"></div>
          </div>
          <svg class="direction_arrow" xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <line x1="5" y1="12" x2="19" y2="12"></line>
            <polyline points="12 5 19 12 12 19"></polyline>
          </svg>
          <div class="phone_landscape">
            <div class="phone_screen"></div>
            <div class="phone_home_button"></div>
          </div>
        </div>

        <div class="tips_container">
          <p class="rotate_hint">请尝试以下操作：</p>
          <ul>
            <li>开启设备<strong>自动旋转</strong>功能，然后将设备横置</li>
            <li>或使用<strong>电脑端(PC)</strong>访问获得完整功能</li>
          </ul>
        </div>
      </div>
      <div class="mobile_notice_footer">
        <button @click="closeNotice" class="continue_btn">继续访问</button>
        <button @click="rememberChoice" class="remember_btn">不再提醒</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'

const showNotice = ref(false)
const isMobile = ref(false)

// 检查是否为移动设备
const checkDevice = () => {
  isMobile.value = window.innerWidth < 400
  
  // 宽度小于800px显示，反之隐藏（除非用户在当前会话中设置了不再提醒）
  if (isMobile.value && !sessionStorage.getItem('show_mobile_notice')) {
    // 小延迟显示，避免初始加载时闪烁
    setTimeout(() => {
      showNotice.value = true
    }, 300)
  } else {
    showNotice.value = false
  }
}

// 关闭弹窗
const closeNotice = () => {
  showNotice.value = false
}

// 记住用户选择，仅在当前会话中不再显示
const rememberChoice = () => {
  sessionStorage.setItem('show_mobile_notice', 'true')
  showNotice.value = false
}

// 监听窗口大小变化
const handleResize = () => {
  checkDevice()
}

onMounted(() => {
  // 初始检查
  checkDevice()
  
  // 添加窗口大小变化事件监听
  window.addEventListener('resize', handleResize)
})

// 不使用onBeforeUnmount钩子移除事件监听
</script>

<style lang="scss" scoped>
.mobile_notice_overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  
  .mobile_notice_content {
    background-color: rgba(255, 255, 255, 0.95);
    width: 90%;
    max-width: 350px;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15), 0 10px 30px rgba(99, 102, 241, 0.1);
    position: relative;
    border: 1px solid rgba(255, 255, 255, 0.2);
    
    .card_glow {
      position: absolute;
      top: 0px;
      left: 0px;
      right: 0px;
      bottom: 0px;
      background: linear-gradient(45deg, rgba(99, 102, 241, 0.3), rgba(139, 92, 246, 0.3));
      border-radius: 20px;
      z-index: -1;
      filter: blur(30px);
      opacity: 0.5;
      animation: glow_pulse 3s infinite alternate;
      pointer-events: none;
    }
    
    .mobile_notice_header {
      padding: 10px;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      
      .close_btn {
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        color: #666;
        width: 30px;
        height: 30px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        
        &:hover {
          color: #333;
          background-color: rgba(0, 0, 0, 0.05);
        }
      }
    }
    
    .mobile_notice_body {
      padding: 5px 20px 20px;
      text-align: center;
      
      .icon {
        color: #6366f1;
        margin-bottom: 15px;
      }
      
      .notice_subtitle {
        font-size: 16px;
        font-weight: 500;
        color: #333;
        margin: 0 0 20px;
        line-height: 1.5;
      }
      
      .tips_container {
        background: rgba(99, 102, 241, 0.05);
        border-radius: 12px;
        padding: 15px;
        margin-top: 20px;
        border: 1px solid rgba(99, 102, 241, 0.1);
        
        .rotate_hint {
          margin-top: 0;
          margin-bottom: 12px;
          font-weight: 500;
          color: #555;
          font-size: 14px;
        }
        
        ul {
          text-align: left;
          margin: 0;
          padding-left: 20px;
          color: #666;
          
          li {
            margin-bottom: 8px;
            line-height: 1.5;
            font-size: 14px;
            
            &:last-child {
              margin-bottom: 0;
            }
          }
        }
      }
      
      strong {
        color: #6366f1;
        font-weight: 600;
      }
      
      .rotate_instruction {
        margin: 20px auto;
        position: relative;
        width: 180px;
        height: 70px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 15px;
        
        .phone_portrait {
          width: 40px;
          height: 70px;
          background-color: #f8fafc;
          border: 2px solid #6366f1;
          border-radius: 10px;
          box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
          position: relative;
          overflow: hidden;
          
          .phone_screen {
            position: absolute;
            top: 6px;
            left: 3px;
            right: 3px;
            height: 75%;
            background-color: #e0e7ff;
            border-radius: 5px;
          }
          
          .phone_home_button {
            position: absolute;
            bottom: 5px;
            left: 50%;
            transform: translateX(-50%);
            width: 12px;
            height: 3px;
            background-color: #94a3b8;
            border-radius: 1px;
          }
        }
        
        .direction_arrow {
          color: #6366f1;
          flex-shrink: 0;
          filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.3));
        }
        
        .phone_landscape {
          width: 70px;
          height: 40px;
          background-color: #f8fafc;
          border: 2px solid #6366f1;
          border-radius: 10px;
          box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
          position: relative;
          overflow: hidden;
          
          .phone_screen {
            position: absolute;
            top: 3px;
            left: 6px;
            right: 6px;
            bottom: 3px;
            background-color: #e0e7ff;
            border-radius: 5px;
          }
          
          .phone_home_button {
            position: absolute;
            right: 5px;
            top: 50%;
            transform: translateY(-50%);
            width: 3px;
            height: 12px;
            background-color: #94a3b8;
            border-radius: 1px;
          }
        }
      }
    }
    
    .mobile_notice_footer {
      display: flex;
      border-top: 1px solid rgba(0, 0, 0, 0.05);
      
      .continue_btn, .remember_btn {
        flex: 1;
        padding: 15px;
        border: none;
        background: none;
        font-size: 14px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.3s ease;
        
        &:hover {
          background-color: rgba(99, 102, 241, 0.05);
        }
      }
      
      .continue_btn {
        color: #666;
        border-right: 1px solid rgba(0, 0, 0, 0.05);
      }
      
      .remember_btn {
        color: #6366f1;
      }
    }
  }
}

@keyframes glow_pulse {
  0% {
    opacity: 0.3;
  }
  100% {
    opacity: 0.6;
  }
}


</style>

